//
//  XS_VipVC.swift
//  XueDao
//
//  Created by 韩云智 on 2020/12/9.
//

import UIKit
import RxSwift
import RxCocoa
import RxDataSources

class XS_queryVipCurriculumM: XS_BaseModel {
    var records: [XS_menuItemCurriculumDtoListM] = []
    var total = 0 // 总记录数
    var size = 10 // 每页数据量
    var current = 0 // 当前页
    var searchCount = false
    var pages = 0 // 总页数
}

class XS_VipVC: XS_BaseVC {
    lazy var tags: [XS_HomeTopM] = []
    var homeTop: XS_HomeTopM?
    private lazy var page = 0
    private lazy var type = -1
    private lazy var isSelect = false
    private lazy var dataPS = PublishSubject<[XS_menuItemCurriculumDtoListM]>()
    private lazy var data: [XS_menuItemCurriculumDtoListM] = []
    private lazy var footer = MJRefreshBackNormalFooter()
    
    lazy var table = UITableView(frame: .zero, style: .grouped)
    
    override func upConfig() {
        shouldNavBarHidden = true
    }
    override func upView() {
        loadCustomBar()
        
        #warning("VVTODO")
        let titleLab = UILabel()
        titleLab.text = "VIP"
        titleLab.font = .systemFont(ofSize: 20, weight: .regular)
        titleLab.textAlignment = .center
        titleLab.textColor = .black
        customBar.addSubview(titleLab)
        titleLab.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
        }
//        let btn12 = UIButton()
//        btn12.layer.cornerRadius = .scale*16
//        btn12.layer.backgroundColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)
//        btn12.frame = CGRect(x: .scale*56, y: .barHeight + (44 - .scale*32)/2, width: .scale*263, height: .scale*32)
//        view.addSubview(btn12)
//        btn12.rx.tap.asDriver()
//            .drive(onNext: { [weak self] in
//                let vc = XS_SearchVC()
//                self?.navigationController?.pushViewController(vc, animated: true)
//            }).disposed(by: disposeBag)
//        do {
//            let imgV = UIImageView(image: UIImage(named: "icon_16px_搜索备份"))
//            imgV.frame = CGRect(x: .scale*10, y: .scale*10, width: .scale*14, height: .scale*14)
//            btn12.addSubview(imgV)
//            let label = UILabel.xsLabel(size: .scale*12, fontName: .regular, color: #colorLiteral(red: 0.768627451, green: 0.7764705882, blue: 0.8039215686, alpha: 1), text: "请输入搜索内容")
//            btn12.addSubview(label)
//            label.snp.makeConstraints { m in
//                m.centerY.equalTo(imgV.snp.centerY)
//                m.left.equalTo(imgV.snp.right).offset(.scale*8)
//            }
//        }
//        let btn2 = XS_NoHighlightBtn()
//        btn2.setBackgroundImage(UIImage(named: "icon_24px_分类"), for: .normal)
//        btn2.frame = CGRect(x: .scale*335, y: .barHeight + (44 - .scale*24)/2, width: .scale*24, height: .scale*24)
//        view.addSubview(btn2)
//        btn2.rx.tap.asDriver()
//            .drive(onNext: { [weak self] in
//                guard XS_Singleton.shared.infoModel != nil else {
//                    XS_NVC.shared.toLogin(false)
//                    return
//                }
//                let vc = XS_HangyeVC()
//                vc.tags = self?.tags ?? []
//                self?.present(vc, animated: true)
//            }).disposed(by: disposeBag)
        
        title = "VIP"
        table.showsVerticalScrollIndicator = false
//        table.bounces = false
        table.contentInsetAdjustmentBehavior = .never
        table.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        table.separatorStyle = .none
        table.rowHeight = .scale*104
        table.sectionHeaderHeight = 0
        table.sectionFooterHeight = 0
        table.tableHeaderView = getHeader()
        table.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: .screenWidth, height: 0.01))
        table.register(XS_VipCell.self, forCellReuseIdentifier: "cell")
        table.register(XS_VipCell.self, forCellReuseIdentifier: "offline")
        view.addSubview(table)
        table.snp.makeConstraints({
            $0.top.equalTo(customBar.snp.bottom)
            $0.left.bottom.right.equalToSuperview()
        })
        
        if XS_Singleton.shared.infoModel?.userBO.userTypeEnum() == XS_UserType.user {
            let openVipV = openVipView()
            view.addSubview(openVipV)
            openVipV.snp.makeConstraints { (make) in
                make.height.equalTo(.scale * 53)
                make.left.bottom.right.equalToSuperview()
            }
            table.snp.updateConstraints {
                $0.bottom.equalTo(-.scale * 55)
            }
        }
        
        let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, XS_menuItemCurriculumDtoListM>>(configureCell: { ds, tv, ip, it in
            let identifier =  it.curriculumType == "offlineCurriculum" ? "offline" : "cell"
            let cell = tv.dequeueReusableCell(withIdentifier: identifier, for: ip) as! XS_VipCell
            cell.isVip = true
            cell.modelPS.onNext(it)
            return cell
        })
        table.rx.modelSelected(XS_menuItemCurriculumDtoListM.self)
            .asDriver()
            .drive(onNext: { item in
                let vc = item.curriculumType == "offlineCurriculum" ? XS_KCXianxiaVC() :  XS_KeChengVC()
                vc.id = "\(item.id)"
                XS_NVC.shared.pushViewController(vc, animated: true)
            }).disposed(by: disposeBag)
        dataPS.asDriver(onErrorJustReturn: [])
            .flatMapLatest { Driver.just([SectionModel<String, XS_menuItemCurriculumDtoListM>(model: "", items: $0)]) }
            .drive(table.rx.items(dataSource: dataSource))
            .disposed(by: disposeBag)
        
        table.mj_footer = footer
        footer.rx.refresh
            .subscribe(onNext: { [weak self] state in
                guard let `self` = self, state == .refreshing else { return }
                self.loadMore()
            }).disposed(by: disposeBag)
        
        XS_Singleton.shared.changeZhengshu = { [weak self] tags in
            self?.tags = tags
            self?.page = 0
            self?.type = -1
            self?.loadMore()
        }
        loadMore()
    }
    
    func loadMore() {
        if page == 0 {
            data.removeAll()
        }
        var param: [String:Any] = [
            "pageNo":page+1
        ]
        let text = isSelect ? "up" : "down"
        switch type {
        case 0: param["price"] = text
        case 1: param["purchaseNum"] = text
        case 2: param["time"] = text
        default: break
        }
        
        XS_NetWork.requestJson("/curriculum/queryVipCurriculum", parameters: param)
            .mapModel(type: XS_queryVipCurriculumM.self)
            .subscribe(onNext: { [weak self] model, resp in
                guard let `self` = self, resp.success, let model = model else { return }
                self.page = model.current
                self.data += model.records
                self.dataPS.onNext(self.data)
                if model.current < model.pages {
                    self.footer.endRefreshing()
                } else {
                    self.footer.endRefreshingWithNoMoreData()
                }
            }).disposed(by: disposeBag)
    }
    
    func getHeader() -> UIView {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: .screenWidth, height: .scale*236))
        
        let cycle = XS_CyclePagerView(frame: CGRect(x: .scale*16, y: .scale*16, width: .scale*343, height: .scale*152))
        cycle.layer.masksToBounds = true
        cycle.layer.cornerRadius = .scale * 4
        view.addSubview(cycle)
        
//        if let model = homeTop {
//            XS_NetWork.requestJson("/banner/queryBanner", parameters: ["relation": model.id, "relationType":model.type])
//                .mapModels(type: XS_QueryBannerM.self)
//                .subscribe(onNext: { models, resp in
//                    guard resp.success else { return }
//                    cycle.data = models
//                    cycle.reloadData()
//                }).disposed(by: disposeBag)
//        }
        XS_NetWork.requestJson("/banner/queryBanner", parameters: [ "relationType":"vip"])
            .mapModels(type: XS_QueryBannerM.self)
            .subscribe(onNext: { models, resp in
                guard resp.success else { return }
                cycle.data = models
                cycle.reloadData()
            }).disposed(by: disposeBag)
        
        let btn1 = getBtn("价格", type: 0)
        view.addSubview(btn1)
        btn1.snp.makeConstraints {
            $0.width.equalTo(.scale*60)
            $0.height.equalTo(.scale*44)
//            $0.left.bottom.equalToSuperview()
            $0.bottom.equalToSuperview()
            $0.left.equalTo(.scale * 8)
        }
        let btn2 = getBtn("销量", type: 1)
        view.addSubview(btn2)
        btn2.snp.makeConstraints {
            $0.width.equalTo(.scale*60)
            $0.height.equalTo(.scale*44)
            $0.centerX.bottom.equalToSuperview()
        }
        let btn3 = getBtn("时间", type: 2)
        view.addSubview(btn3)
        btn3.snp.makeConstraints {
            $0.width.equalTo(.scale*60)
            $0.height.equalTo(.scale*44)
//            $0.right.bottom.equalToSuperview()
            $0.bottom.equalToSuperview()
            $0.right.equalTo(-.scale * 8)
        }
        let btns = [btn1, btn2, btn3]
        let observables = btns.map { button in button.rx.tap.map { button } }
        let selected = Observable.from(observables).merge()
        for button in btns {
            selected.map { $0 === button && $0.isSelected }
                .bind(to: button.rx.isSelected)
                .disposed(by: disposeBag)
        }
        
        return view
    }
    
    private func getBtn(_ text: String, type: Int) -> UIButton {
        let btn = QMUIButton()
        btn.setTitle(text, for: .normal)
        btn.setTitleColor(#colorLiteral(red: 0.4470588235, green: 0.4666666667, blue: 0.4862745098, alpha: 1), for: .normal)
        btn.titleLabel?.font = .xsFont(name: .regular, .scale*14)
        btn.setImage(UIImage(named: "icon_12px_更多_2"), for: .normal)
        btn.setImage(UIImage(named: "icon_12px_更多_1"), for: .selected)
        btn.imagePosition = .right
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: .scale*4, bottom: 0, right: 0)
        btn.rx.tap.asDriver()
            .map { !btn.isSelected }
            .drive(onNext: { [weak self] set in
                self?.page = 0
                self?.type = type
                self?.isSelect = set
                self?.loadMore()
                btn.isSelected = set
            }).disposed(by: disposeBag)
        return btn
    }
    
    func openVipView() -> UIView {
        let openVipView = UIView()
        
        let imgView = UIImageView.init(image: UIImage.init(named: "huiyuan"))
        openVipView.addSubview(imgView)
        imgView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        let openVipTap = UITapGestureRecognizer()
        openVipView.addGestureRecognizer(openVipTap)
        openVipTap.addTarget(self, action: #selector(openVip))
        
        return openVipView
    }
    
    @objc func openVip() {
        let vipVC = XS_VIPVC()
        navigationController?.pushViewController(vipVC, animated: true)
    }
}

class XS_VipCell: XS_BaseTCell {
    lazy var isVip = false
    lazy var modelPS = PublishSubject<XS_menuItemCurriculumDtoListM>()
    
    public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        upView(reuseIdentifier)
    }
    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func getLineEdgeInsets() -> UIEdgeInsets {
        UIEdgeInsets(top: 0, left: .scale*16, bottom: 0, right: -.scale*16)
    }
    func upView(_ reuseIdentifier: String?) {
        super.upView()
        
        let view = reuseIdentifier == "offline" ? getXianxia() : getXianShang()
        contentView.addSubview(view)
        view.snp.makeConstraints({
            $0.edges.equalTo(UIEdgeInsets(top: .scale*16, left: .scale*16, bottom: 0, right: .scale*16))
        })
    }
    
    func getXianxia() -> UIView {
        let view = UIView()
        
        let imgV = UIImageView()
        imgV.frame = CGRect(x: 0, y: 0, width: .scale*100, height: .scale*72)
        view.addSubview(imgV)
        imgV.layer.cornerRadius = .scale*4
        imgV.clipsToBounds = true
        
        let tagsView = UIView(frame: CGRect(x: 0, y: 0, width: 49, height: 18) * .scale)
        imgV.addSubview(tagsView)
        let sLayer = CAShapeLayer()
        sLayer.fillColor = #colorLiteral(red: 0.9294117647, green: 0.3960784314, blue: 0.2470588235, alpha: 1)
        sLayer.path = UIBezierPath(roundedRect: tagsView.bounds, byRoundingCorners: [.bottomRight], cornerRadii: CGSize(width: 4, height: 4) * .scale).cgPath
        tagsView.layer.addSublayer(sLayer)
        let tagLabel = UILabel.xsLabel(size: .scale*10, fontName: .medium, color: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), alignment: .center, text: "限时免费")
        tagsView.addSubview(tagLabel)
        tagLabel.snp.makeConstraints({
            $0.center.equalToSuperview()
        })
        
        let layerView = UIView()
        layerView.frame = CGRect(x: 0, y: 0, width: .scale*45, height: .scale*18)
        layerView.corner(byRoundingCorners: .bottomRight, radii: .scale*4)
        layerView.alpha = 1
        // fillCode
        let bglayer1 = CAGradientLayer()
        bglayer1.colors = [UIColor(red: 1, green: 0.91, blue: 0.73, alpha: 1).cgColor, UIColor(red: 0.98, green: 0.84, blue: 0.59, alpha: 1).cgColor]
        bglayer1.locations = [0, 1]
        bglayer1.frame = layerView.bounds
        layerView.layer.addSublayer(bglayer1)
        bglayer1.startPoint = CGPoint(x: 1.00, y: 0.50)
        bglayer1.endPoint = CGPoint(x: -0.00, y: 0.50)
        imgV.addSubview(layerView)
        let label = UILabel.xsLabel(size: .scale*10, fontName: .medium, color: #colorLiteral(red: 0.5803921569, green: 0.3490196078, blue: 0, alpha: 1), text: "VIP免费")
        layerView.addSubview(label)
        label.snp.makeConstraints({
            $0.center.equalToSuperview()
        })
        
        let label1 = UILabel.xsLabel(size: .scale*14, fontName: .medium, color: #colorLiteral(red: 0.2829915285, green: 0.3015331626, blue: 0.3147756159, alpha: 1))
        view.addSubview(label1)
        label1.snp.makeConstraints {
            $0.top.equalToSuperview()
            $0.left.equalTo(imgV.snp.right).offset(.scale*12)
            $0.right.lessThanOrEqualToSuperview().offset(-.scale*8)
        }
        let icon = UIImageView(image: UIImage(named: "icon_12px_定位"))
        icon.frame = CGRect(x: .scale*112, y: .scale*28, width: .scale*12, height: .scale*12)
        view.addSubview(icon)
        let label2 = UILabel.xsLabel(size: .scale*12, fontName: .regular, color: #colorLiteral(red: 0.4470588235, green: 0.4666666667, blue: 0.4862745098, alpha: 1))
        view.addSubview(label2)
        label2.snp.makeConstraints {
            $0.centerY.equalTo(icon.snp.centerY)
            $0.left.equalTo(icon.snp.right).offset(.scale*4)
            $0.right.lessThanOrEqualToSuperview().offset(-.scale*8)
        }
        let label3 = UILabel.xsLabel(size: .scale*12, fontName: .medium, color: #colorLiteral(red: 0.9294117647, green: 0.3960784314, blue: 0.2470588235, alpha: 1))
        view.addSubview(label3)
        label3.snp.makeConstraints {
            $0.bottom.equalTo(-.scale*16)
            $0.left.equalTo(imgV.snp.right).offset(.scale*12)
            $0.width.lessThanOrEqualTo(.scale*150)
        }
        let fm = DateFormatter()
        fm.dateFormat = "yyyy-MM-dd HH:mm:ss"
        
        let label4 = UILabel()
        
        view.addSubview(label4)
        label4.snp.makeConstraints({
//            $0.right.equalToSuperview()
            $0.left.equalTo(label3.snp.right).offset(0)
            $0.bottom.equalTo(-.scale*16)
        })
        
        let line = UIView()
        line.backgroundColor = #colorLiteral(red: 0.9019607843, green: 0.9137254902, blue: 0.9450980392, alpha: 1)
        view.addSubview(line)
        line.snp.makeConstraints({
            $0.left.bottom.right.equalToSuperview()
            $0.height.equalTo(1)
        })
        
        modelPS.subscribe(onNext: { [weak self] item in
            guard let `self` = self else { return }
            imgV.sd_setImage(with: URL(string: item.curriculumImgUrl))
            let p: String
            if self.isVip {
                p = (Double(item.vipPrice) ?? 0)>0 ? item.vipPrice : ""
            } else {
                (p, _) = xsGetPrice(vipIsFree: item.vipIsFree, isFree: item.isFree, vipPrice: item.vipPrice, discountPrice: item.discountPrice, price: item.price)
            }
            let text = NSMutableAttributedString()
            if p.count > 0 {
                let attr = NSMutableAttributedString(string: " | ￥")
                attr.yy_font = .xsFont(name: .medium, .scale*12)
                text.append(attr)
            }
            do {
                let attr = NSMutableAttributedString(string: p.count > 0 ? p : " | 免费")
                attr.yy_font = .xsFont(name: .medium, .scale*12)
                text.append(attr)
            }
            text.yy_color = #colorLiteral(red: 0.9294117647, green: 0.3960784314, blue: 0.2470588235, alpha: 1)
            text.yy_alignment = .right
            label4.attributedText = text
            if let date = fm.date(from: item.startTime) {
                let fm1 = DateFormatter()
//                fm1.dateFormat = "d.M EE"
                fm1.dateFormat = "MM-dd"
                label3.text = fm1.string(from: date)
            }
            label2.text = item.offlineAddress
            label1.text = item.curriculumName
            tagsView.isHidden = true
            layerView.isHidden = true
            if item.isFree == "userFree" {
                tagsView.isHidden = false
            } else if item.vipIsFree == "vipFree" {
                layerView.isHidden = false
            }
        }).disposed(by: disposeBag)
        
        return view
    }
    
    func getXianShang() -> UIView {
        let view = UIView()
        
        let imgV = UIImageView()
        imgV.frame = CGRect(x: 0, y: 0, width: .scale*100, height: .scale*72)
        view.addSubview(imgV)
        imgV.layer.cornerRadius = .scale*4
        imgV.clipsToBounds = true
        
        let layerView = UIView()
        layerView.frame = CGRect(x: 0, y: 0, width: .scale*45, height: .scale*18)
        layerView.corner(byRoundingCorners: .bottomRight, radii: .scale*4)
        layerView.alpha = 1
        // fillCode
        let bglayer1 = CAGradientLayer()
        bglayer1.colors = [UIColor(red: 1, green: 0.91, blue: 0.73, alpha: 1).cgColor, UIColor(red: 0.98, green: 0.84, blue: 0.59, alpha: 1).cgColor]
        bglayer1.locations = [0, 1]
        bglayer1.frame = layerView.bounds
        layerView.layer.addSublayer(bglayer1)
        bglayer1.startPoint = CGPoint(x: 1.00, y: 0.50)
        bglayer1.endPoint = CGPoint(x: -0.00, y: 0.50)
        imgV.addSubview(layerView)
        
        let label = UILabel.xsLabel(size: .scale*10, fontName: .medium, color: #colorLiteral(red: 0.5803921569, green: 0.3490196078, blue: 0, alpha: 1), text: "VIP免费")
        layerView.addSubview(label)
        label.snp.makeConstraints({
            $0.center.equalToSuperview()
        })
        
        
        let label1 = UILabel.xsLabel(size: .scale*14, fontName: .medium, color: #colorLiteral(red: 0.2829915285, green: 0.3015331626, blue: 0.3147756159, alpha: 1), text: "可视化程序设计及应用")
        view.addSubview(label1)
        label1.snp.makeConstraints {
            $0.top.equalToSuperview()
            $0.left.equalTo(imgV.snp.right).offset(.scale*12)
            $0.right.lessThanOrEqualToSuperview().offset(-.scale*8)
        }
        let label2 = UILabel.xsLabel(size: .scale*12, fontName: .regular, color: #colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1), text: "1242人加入学习")
        view.addSubview(label2)
        label2.snp.makeConstraints {
            $0.top.equalTo(label1.snp.bottom).offset(.scale*6)
            $0.left.equalTo(imgV.snp.right).offset(.scale*12)
            $0.right.lessThanOrEqualToSuperview().offset(-.scale*8)
        }
        let label3 = UILabel.xsLabel(size: .scale*12, fontName: .semibold, color: #colorLiteral(red: 0.9294117647, green: 0.3960784314, blue: 0.2470588235, alpha: 1), text: "共9节 | 免费")
        view.addSubview(label3)
        label3.snp.makeConstraints {
            $0.bottom.equalTo(-.scale*16)
            $0.left.equalTo(imgV.snp.right).offset(.scale*12)
            $0.width.lessThanOrEqualTo(.scale*150)
        }
        
        let label4 = UILabel.xsLabel(size: .scale * 14, fontName: .medium, color: UIColor(red: 0.93, green: 0.40, blue: 0.25, alpha: 1.0), alignment: .right, lines: 2, text: "￥1999")
        view.addSubview(label4)
        label4.snp.makeConstraints { (make) in
            make.right.equalTo(-.scale * 12)
            make.bottom.equalTo(-.scale * 16)
        }
        
        let label5 = UILabel.xsLabel(size: .scale * 8, fontName: .medium, color: UIColor(red: 0.60, green: 0.60, blue: 0.60, alpha: 1.0), alignment: .right, lines: 1, text: "￥1888")
        view.addSubview(label5)
        label5.snp.makeConstraints { (make) in
            make.right.equalTo(label4.snp.left)
            make.bottom.equalTo(-.scale * 16)
        }
        
        let line = UIView()
        line.backgroundColor = #colorLiteral(red: 0.9019607843, green: 0.9137254902, blue: 0.9450980392, alpha: 1)
        view.addSubview(line)
        line.snp.makeConstraints({
            $0.left.bottom.right.equalToSuperview()
            $0.height.equalTo(1)
        })
        
        modelPS.subscribe(onNext: { [weak self] item in
            guard let `self` = self else { return }
            let vipIsFree = item.vipIsFree == "vipFree"
            let p: String
            if self.isVip {
                p = Double(item.vipPrice)! > 0 && !vipIsFree ? item.vipPrice : ""
            } else {
                (p, _) = xsGetPrice(vipIsFree: item.vipIsFree, isFree: item.isFree, vipPrice: item.vipPrice, discountPrice: item.discountPrice, price: item.price)
            }
//            layerView.isHidden = !vipIsFree
            label.text = vipIsFree ? "VIP免费" : "VIP特惠"
            imgV.sd_setImage(with: URL(string: item.curriculumImgUrl))
            label1.text = item.curriculumName
            label2.text = "\(item.purchaseNum)人加入学习"
            label3.text = "共\(item.curriculumNum)节"
            
            let hyTitleStr = "会员价\n"
            let vipPriceStr = "￥\(item.vipPrice)"
            let priceMuAttStr = NSMutableAttributedString.init(string: hyTitleStr + vipPriceStr)
            priceMuAttStr.addAttributes([.font : UIFont.boldSystemFont(ofSize: .scale * 8),
                                         .foregroundColor : UIColor(red: 0.93, green: 0.40, blue: 0.25, alpha: 1.0)],
                                        range: NSRange.init(location: 0, length: hyTitleStr.count))
            priceMuAttStr.addAttributes([.font : UIFont.boldSystemFont(ofSize: .scale * 14),
                                         .foregroundColor : UIColor(red: 0.93, green: 0.40, blue: 0.25, alpha: 1.0)],
                                        range: NSRange.init(location: hyTitleStr.count, length: vipPriceStr.count))
            
            let yjPriceStr = "￥\(item.price)"
            let yjMuAttStr = NSMutableAttributedString.init(string: yjPriceStr)
            yjMuAttStr.yy_strikethroughStyle = .single
            yjMuAttStr.yy_strikethroughColor = UIColor(red: 0.60, green: 0.60, blue: 0.60, alpha: 1.0)

            let freeStr = "会员免费"
            let freeMuAttStr = NSMutableAttributedString.init(string: freeStr)
            freeMuAttStr.addAttributes([.font : UIFont.boldSystemFont(ofSize: .scale * 12),
                                         .foregroundColor : UIColor(red: 0.93, green: 0.40, blue: 0.25, alpha: 1.0)],
                                        range: NSRange.init(location: 0, length: freeStr.count))
            
            label4.attributedText = p.count > 0 ? priceMuAttStr : freeMuAttStr
            label5.attributedText = p.count > 0 ? yjMuAttStr : NSMutableAttributedString.init(string: "")
        }).disposed(by: disposeBag)
        
        return view
    }
}
